<script>
	export default {
		onLaunch: function() {
			// #ifdef MP-WEIXIN
			uni.showShareMenu({
				menus: ["shareAppMessage", "shareTimeline"]
			})
			// #endif
			//初始化mqtt
			this.mqtt.initMqtt()
			this.mqtt.addSub("abc")

			// 判断是否登录e
			// 更新 start
			// #ifdef APP-PLUS
			const version = this.$version
			this.apis.commonApi.getAppVersion().then(res => {
				let newVersion = res.rows[0].appVersion
				if (newVersion !== version) {
					uni.showModal({
						title: '更新提示',
						content: '当前有新版本，是否更新？',
						success(op) {
							if (op.confirm) {
								plus.runtime.openURL("http://www.xibushigu.com:9555/", res => {
									uni.showToast({
										title: '打开当前地址出错啦，请稍后再试',
										icon: 'none'
									});
								})
							} else {

							}
						}
					})
				}
			})
			// #endif

			// #ifdef MP-WEIXIN
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				console.log(res.hasUpdate);
			});

			updateManager.onUpdateReady(function(res) {
				uni.showModal({
					title: '更新提示！',
					content: '有新的版本了，是否重启应用？',
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});

			});

			updateManager.onUpdateFailed(function(res) {
				uni.showModal({
					title: '更新失败',
					content: '更新失败，请手动删除小程序重新进入？',
					success(res) {}
				});
			});
			// #endif

			// 更新 end

			// 消息推送 a
			// #ifdef APP-PLUS
			var inf = plus.push.getClientInfo();
			console.log(inf);
			if (uni.getSystemInfoSync().platform == 'android') {
				this.clientId1 = inf.clientid;
				uni.setStorageSync("clientId", inf.clientid)
				this.tokenType = 'android';
			} else if (uni.getSystemInfoSync().platform == 'ios') {
				this.clientId = inf.token;
				this.tokenType = 'ios';
			}
			plus.push.addEventListener(
				'receive',
				function(msg) {
					console.log(msg);
					if (msg.aps) {
						// Apple APNS message
						//APNS下发的消息，应用在前台
					} else {
						//其它情况接收消息
					}
				},
				false
			);
			var msgs = plus.push.getAllMessage();
			// #endif

			// uni.getProvider({
			// 	service: 'push',
			// 	success: e => {
			// 		that.provider = e.provider;
			// 		uni.subscribePush({
			// 			provider: that.provider[0],
			// 			success: function(res) {
			// 				var inf = plus.push.getClientInfo();
			// 				if (uni.getSystemInfoSync().platform == 'android') {
			// 					that.clientId1 = inf.clientid;
			// 					that.tokenType = 'android';
			// 					console.log(that.clientId1)
			// 				} else if (uni.getSystemInfoSync().platform == 'ios') {
			// 					that.clientId = inf.token;
			// 					that.tokenType = 'ios';
			// 					console.log(that.clientId1)
			// 				}
			// 				uni.onPush({
			// 					provider: that.provider[0],
			// 					success: e => {},
			// 					callback: e => {}
			// 				});
			// 			},
			// 			fail: function(err) {
			// 				uni.onPush({
			// 					provider: that.provider[0],
			// 					success: e => {},
			// 					callback: e => {}
			// 				});
			// 			}
			// 		});
			// 	},
			// 	fail: e => {

			// 		uni.subscribePush({
			// 			provider: that.provider[0],
			// 			success: function(res) {
			// 				uni.onPush({
			// 					provider: that.provider[0],
			// 					success: e => {},
			// 					callback: e => {}
			// 				});
			// 			},
			// 			fail: function(err) {
			// 				uni.onPush({
			// 					provider: that.provider[0],
			// 					success: e => {},
			// 					callback: e => {}
			// 				});
			// 			}
			// 		});
			// 	}
			// });
			// 消息推送 e

			// let isLogin = uni.getStorageSync("isLogin")
			// if(isLogin){
			// 	uni.switchTab({
			// 		url: '/pages/home/home'
			// 	})
			// }

		},
		onShow(op) {

		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";

	* {
		box-sizing: border-box;
	}


	.page {
		width: 100vw;
		position: relative;
		overflow-x: hidden;
		box-sizing: border-box;
		padding: 20rpx 20rpx;
		background: #F8F8F8;
		font-family: PingFang-SC-Medium, PingFang-SC;
	}


	.icon_radius {
		border-radius: 10rpx;
	}

	page {
		background: #F8F8F8;
		font-family: PingFang-SC-Medium, PingFang-SC;
	}

	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.icon-shipin:before {
		content: "\f0024";
	}

	.icon-tupian:before {
		content: "\e650";
	}

	.icon-guanyuwomen:before {
		content: "\e608";
	}

	.icon-ziyuan:before {
		content: "\e60d";
	}


	/deep/.u-select__header__confirm {
		color: #44D94B !important;
	}

	/deep/ .u-calendar__action {
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
